#include "wxsspinbutton.h"
#include <wx/spinbutt.h>

namespace {
  wxsRegisterItem<wxsSpinButton> Reg( _T( "SpinButton" ), _T( "翻页按钮" ), wxsTWidget, _T( "标准" ), 100 );
  WXS_ST_BEGIN( wxsSpinButtonStyles, _T( "wxSP_VERTICAL|wxSP_ARROW_KEYS" ) )
  WXS_ST_CATEGORY( "wxSpinButton" )
  WXS_ST( wxSP_HORIZONTAL )
  WXS_ST( wxSP_VERTICAL )
  WXS_ST( wxSP_ARROW_KEYS )
  WXS_ST( wxSP_WRAP )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsSpinButtonEvents )
  WXS_EVI( EVT_SPIN, wxEVT_SCROLL_THUMBTRACK, wxSpinEvent, Change )
  WXS_EVI( EVT_SPIN_UP, wxEVT_SCROLL_LINEUP, wxSpinEvent, ChangeUp )
  WXS_EVI( EVT_SPIN_DOWN, wxEVT_SCROLL_LINEDOWN, wxSpinEvent, ChangeDown )
  WXS_EV_END()
}

wxsSpinButton::wxsSpinButton( wxsItemResData* Data ):
  wxsWidget( Data, &Reg.Info, wxsSpinButtonEvents, wxsSpinButtonStyles ), Value( 0 ), Min( 0 ), Max( 100 ) {}

void wxsSpinButton::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
  case wxsCPP: {
    AddHeader( _T( "<wx/spinbutt.h>" ), GetInfo().ClassName, 0 );
    AddHeader( _T( "<wx/spinbutt.h>" ), _T( "wxSpinEvent" ), 0 );
    Codef( _T( "%C(%W, %I, %P, %S, %T, %N);\n" ) );
    if( Value ) {
      Codef( _T( "%ASetValue(%d);\n" ), Value );
    }
    if( Max > Min ) {
      Codef( _T( "%ASetRange(%d, %d);\n" ), Min, Max );
    }
    BuildSetupWindowCode();
    return;
  }
  case wxsUnknownLanguage:
  default: {
    wxsCodeMarks::Unknown( _T( "wxsSpinButton::OnBuildCreatingCode" ), GetLanguage() );
  }
  }
}

wxObject* wxsSpinButton::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxSpinButton* Preview = new wxSpinButton( Parent, GetId(), Pos( Parent ), Size( Parent ), Style() );
  if( Value ) {
    Preview->SetValue( Value );
  }
  if( Max > Min ) {
    Preview->SetRange( Min, Max );
  }
  return SetupWindow( Preview, Flags );
}

void wxsSpinButton::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_LONG( wxsSpinButton, Value, _T( "Value" ), _T( "默认值" ), 0 )
  WXS_LONG( wxsSpinButton, Min, _T( "Min Value" ), _T( "min" ), 0 )
  WXS_LONG( wxsSpinButton, Max, _T( "Max Value" ), _T( "max" ), 0 )
}
